---
title: GetUserEmail
summary: Reads a user's mail attribute from the caller-selected directory domain.
status: draft
owner: "Not determined from source"
last_reviewed: 2026-09-22
---

# GetUserEmail (OP-12)

## Request and response

| Part | Type | Description |
| --- | --- | --- |
| `inUserId` | `String` | The `SamAccountName` to look up. |
| `inExternalDomain` | `Boolean` | Selects `external.saif.com` when `True`, `corp.saif.com` when `False` ([BR-07](../business-rules.md#br-07-the-directory-domain-is-selected-by-the-caller)). |

| Part | Type | Description |
| --- | --- | --- |
| `<return>` | `ADServiceResponse` | `Response` (`EResponse` code) and `Message` (the `mail` attribute value on success). |

## WebMethod attributes

`<WebMethod()>` — bare, no arguments supplied.

## Steps

1. No access check is performed ([BR-06](../business-rules.md#br-06-read-only-directory-queries-are-not-access-controlled)).
2. Initialize `myStruc.Response = Success`, `myStruc.Message = String.Empty`.
3. In a `Try` block, call H2 `GetUserPrincipal` with the caller-supplied `inExternalDomain` ([BR-07](../business-rules.md#br-07-the-directory-domain-is-selected-by-the-caller)).
   - If the principal is `Nothing`, set `Response = UserDoesNotExist`.
   - Otherwise, get the underlying `DirectoryEntry` (`userPrin.GetUnderlyingObject`) and assign `Message = de.Properties.Item("mail").Value`, a late-bound COM property read ([BR-27](../business-rules.md#br-27-a-directory-attribute-query-returns-the-value-or-userdoesnotexist)).
4. `Catch`: set `Response = Failure`, `Message = ex.Message`.
5. `Finally`: release `userPrin` and `de`.
6. Return the `ADServiceResponse` sentinel.

An unset `mail` attribute is not distinguished from any other directory exception: both surface as `Failure` with a .NET null-reference or cast exception message rather than a dedicated response code*.

## Process flow

```mermaid
flowchart TD
    A["Call GetUserEmail"] --> B["GetUserPrincipal<br>caller-selected domain"]
    B -->|"Nothing"| C["Response = UserDoesNotExist"]
    B -->|"Found"| D["Read mail attribute<br>via GetUnderlyingObject"]
    D -->|"Success"| E["Message = mail value<br>Response = Success"]
    D -->|"Exception"| F["Response = Failure<br>Message = ex.Message"]
    C --> G["Return ADServiceResponse"]
    E --> G
    F --> G
```

## Shared state effects

None — this operation touches no process-wide state; all locals are per-request.

## Error handling

This operation never faults: every failure path, including an unset `mail` attribute or a directory exception, is caught and mapped to `Response = Failure` with `ex.Message` in `Message`. See [Faults](../faults.md) for the service-wide fault model.

## Authorization

None in code. This is one of the eleven ungated operations that disclose directory data to any caller who can reach the endpoint (see [Authentication and authorization](../authentication-authorization.md) and [Tech debt](../tech-debt.md)).

## Related documentation
- [Service index](../index.md)
- [Overview](../overview.md)
- [Architecture](../architecture.md)
- [Activation and hosting](../activation-hosting.md)
- [Operations](../operations.md)
- [Operations and processes](../operations-processes.md)
- [Business rules](../business-rules.md)
- [Authentication and authorization](../authentication-authorization.md)
- [Configuration](../configuration.md)
- [Dependencies](../dependencies.md)
- [Faults](../faults.md)
- [Operational runbook](../operational-runbook.md)
- [Tech debt](../tech-debt.md)

> **Note:** Statements marked with * were inferred from code structure, naming conventions, or
> contextual evidence where direct confirmation was not available in source artifacts. Statements
> marked with ** could not be confirmed; treat as unknown until verified.

## Sources
- `src\ADUserServices\clsADUserServices.asmx.vb` (lines 526-554)
